//页面适配控制
function pageFlex(n){
  window.onresize = function(){
    location.reload()
  }
  if(n==1){             //1. 页面尺寸就是设计稿尺寸 1920*1080
    $("head").append(`
      <style>
      body{
        width:1920px;
        height:1080px;
      }
      </style>
    `)
    window.KO = 1; 
    $("html").css('font-size','100px');    
    return false;
  }
  var width = $('html').width();
  if(n==2){              //2. 页面尺寸随宽度变化，单位rem
    window.KO = width/1920; 
    $("html").css('font-size',KO*100+'px');
  }
  if(n==3){              //3. 页面先放大2倍，再缩小一倍，防止局部放大后模糊
    $("head").append(`
      <style>
      body{
        overflow: hidden;
        height: 200%;
        width: 200%;
        overflow: hidden;
        transform-origin: left top;
        transform: scale(0.5);  
      }
      .dbsp .ZDtoMAP_map{
        width: 50%;
        height: 200vh;
        margin-top: -135vh;
        transform-origin: left top;
        transform: scale(2);
      }
      .dbsp option{
        font-size: 0.07rem;
        transform: translate3d(0,0,0) scale(0.5);
      }
      </style>
    `)  
    width = width*2;
    window.KO = width/1920; 
    $("html").css('font-size',KO*100+'px').addClass("dbsp");
  }
}



//放大缩小操作
$(document).on("click", ".temp_move_btn",function(){
  var mc = $(".move_center");
  if(mc.length == 0){
    $(".zhezhao").fadeIn(500);
    var parent = $(this).parents(".temp");
    var scale = parent.attr("scale") || '1.8';
    parent.addClass("move_center"); 
    parent[0].style = "z-index:999;transform: translate(-50%,-50%) scale("+scale+");"
  }else{
    $(".zhezhao").fadeOut(500);
    mc[0].style = "z-index:999;transform: translate(0%,0%) scale(1);"
    mc.removeClass("move_center");
    setTimeout(function(){
      mc[0].style = ""
    },500)
  }
})
$(".zhezhao").click(function(){
  var mc = $(".move_center");
  $(".zhezhao").fadeOut(500);
  mc[0].style = "z-index:999;transform: translate(0%,0%) scale(1);"
  mc.removeClass("move_center");
  setTimeout(function(){
    mc[0].style = ""
  },500)  
})



//实时更改中心地图大小函数
function setSvgImgHeight(){
  var svgBox = $(".svg-box");
  var sHeight =svgBox.height();
  var w = sHeight*526*0.9/331;
  $("#svgImg").width(w);  
}



//列表信息滚动封装
function addItem(el,html){
  let li1 = $(el).children().eq(0);
  $(el).append( html || li1.clone(true) );
  li1.css('transition', '1s');
  li1.css("margin-top",-li1.outerHeight(true));
  setTimeout(function(){
    li1.remove()
  },1500)
}



/*--------------------------以下是工具函数------------------------*/
//获取随机数封装
function rdm(min, max) {
  return parseInt(Math.random() * (max - min) + min);
}

//随机范围封装
function SJ(n,w,f){
  if(f == -1) return n-rdm(0,w);                               //SJ(20,5,-1)  20在 15-20 之间波动
  if(f == 1) return n+rdm(0,w);                                //SJ(20,5,1)   20在 20-25 之间波动
  if(f == 0) return rdm(1,10)<=5 ? n-rdm(0,w) : n+rdm(0,w);    //SJ(20,5,1)   20在 15-25 之间波动
}

//数组随机排序
function shuffle(arr) { 
  var i = arr.length, t, j; 
  while (i) { 
    j = Math.floor(Math.random() * i--); 
    t = arr[i]; 
    arr[i] = arr[j]; 
    arr[j] = t; 
  } 
} 


//svg元素添加 class
$.fn.addSvgClass = function(className) {
  return this.each(function() {
    var attr = $(this).attr('class') || "";
    if (!$(this).hasClass(className)) {
      $(this).attr('class', $.trim(attr + ' ' + className))
    }
  })
};


//svg元素删除 class
$.fn.removeSvgClass = function(className) {
  return this.each(function() {
    var attr = $(this).attr('class') || "";
    var arr = attr.split(" ");
    var curr = [];
    $.each(arr,function(){
      if(this != className){
        curr.push(this)
      }
    })
    $(this).attr('class', curr.join(" "))
  })
};


//日期格式化函数
function dateForm(str){
  var d = str ? new Date(str) : new Date()
  var ps = function(num){
    return 'a'.padStart ? num.toString().padStart(2, '0') : (num<10 ? '0'+ num : num)
  }
  var year = d.getFullYear()
  var month = d.getMonth()+1  
  var day = d.getDate()
  var hour = d.getHours()
  var minutes = d.getMinutes()
  var seconds = d.getSeconds()
  let week = d.getDay()
  var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'] 
  window.dateInfo = {
    date: d,
    year: year,
    month: month,
    day: day,
    hour: hour,
    minutes: minutes,
    seconds: seconds,
    week: week,
    time: d.getTime(),
    Y: ps(year),
    M: ps(month),
    D: ps(day),
    H: ps(hour),
    M: ps(minutes),
    S: ps(seconds),
    W: weekArr[week],
    YMDHMS: year + '-' + ps(month) + '-' + ps(day) + ' ' + ps(hour) + ":" + ps(minutes) + ":" + ps(seconds),
    YMD: year + '-' + ps(month) + '-' + ps(day),
    HMS: ps(hour) + ":" + ps(minutes) + ":" + ps(seconds),
  }  
  return window.dateInfo 
}


// 页面右上角时间处理
function _0(n){
  if(n<10){
    return '0'+n;
  }else{
    return n
  }
}

var d = dateForm();
$(function(){
  $("#top_date").html(d.W+" "+d.Y+"年"+d.month+"月"+d.day)
})
setInterval(function(){
  var d = new Date();
  var h = d.getHours();
  $("#top_time").html( _0(d.getHours())+' : '+_0(d.getMinutes())+' : '+_0(d.getSeconds()) );
  if(d.getHours() == 0 && d.getMinutes() == 0 && d.getSeconds() == 1){
    showDate(d);
  }
},1000)